{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "data": {
      "text/plain": "array([24.49712457, 20.43464006, 27.04645755])"
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cv2\n",
    "import numpy as np\n",
    "import random\n",
    "import os\n",
    "\n",
    "lower_red = np.array((54, 22, 82))\n",
    "upper_red = np.array((255,250, 250))\n",
    "sum = np.zeros((512,512, 3), dtype='float')\n",
    "counter = 0\n",
    "r = '/home/ubuntu/code/ssd.pytorch/data/pollen_data_multi_classes/train/JPEGImages/'\n",
    "for i in os.listdir(r):\n",
    "    im = cv2.imread(r + i)\n",
    "    h,w,_ = im.shape\n",
    "    if h!=512 or w!=512:\n",
    "        continue\n",
    "    counter+=1\n",
    "    hsv = cv2.cvtColor(im, cv2.COLOR_BGR2HSV)\n",
    "    mask = cv2.inRange(hsv, lower_red, upper_red)\n",
    "\n",
    "    res = cv2.bitwise_and(im, im, mask=mask)\n",
    "    sum+=res\n",
    "sum /=counter\n",
    "m = sum.mean(axis=(0,1))\n",
    "m\n",
    "# im = im.astype('float')\n",
    "# im *= (random.random() + 0.5)\n",
    "# im[im>255] = 255\n",
    "# im = im.astype('uint8')\n",
    "\n",
    "\n",
    "#\n",
    "# cv2.imshow('hh', res)\n",
    "#\n",
    "# cv2.waitKey(0)\n",
    "# cv2.destroyAllWindows()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "numpy.ndarray"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# import numpy\n",
    "#\n",
    "# a = type(numpy.array([1]))\n",
    "# a"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "pycharm-d8472df8",
   "language": "python",
   "display_name": "PyCharm (ssd.pytorch)"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}